Telegram Group & Telegram Channel
136. Binary search using recursion

#include<stdio.h>

int binary(int arr[], int n, int search, int l, int u);

int main()
{
int arr[10], i, n, search, c, l, u;

printf("Enter the size of an array : ");
scanf("%d", &n);

for (i = 0; i < n; i++)
{
printf("Enter the element %d : ", i+1);
scanf("%d", &arr[i]);
}

printf("Enter the number to be search: ");
scanf("%d", &search);

l = 0, u = n - 1;
c = binary(arr, n, search, l, u);

if (c == 0)
printf("Number not found.");
else
printf("Number found.");

return 0;
}

int binary(int arr[], int n, int search, int l, int u)
{

int mid, c = 0;

if (l <= u)
{
mid = (l + u) / 2;
if (search == arr[mid])
{
c = 1;
}
else if (search < arr[mid])
{
return binary(arr, n, search, l, mid - 1);
}
else
return binary(arr, n, search, mid + 1, u);
}
else
return c;
}
@C_Codings



tg-me.com/C_Codings/198
Create:
Last Update:

136. Binary search using recursion

#include<stdio.h>

int binary(int arr[], int n, int search, int l, int u);

int main()
{
int arr[10], i, n, search, c, l, u;

printf("Enter the size of an array : ");
scanf("%d", &n);

for (i = 0; i < n; i++)
{
printf("Enter the element %d : ", i+1);
scanf("%d", &arr[i]);
}

printf("Enter the number to be search: ");
scanf("%d", &search);

l = 0, u = n - 1;
c = binary(arr, n, search, l, u);

if (c == 0)
printf("Number not found.");
else
printf("Number found.");

return 0;
}

int binary(int arr[], int n, int search, int l, int u)
{

int mid, c = 0;

if (l <= u)
{
mid = (l + u) / 2;
if (search == arr[mid])
{
c = 1;
}
else if (search < arr[mid])
{
return binary(arr, n, search, l, mid - 1);
}
else
return binary(arr, n, search, mid + 1, u);
}
else
return c;
}
@C_Codings

BY C Language πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/C_Codings/198

View MORE
Open in Telegram


C Language ‍ Telegram | DID YOU KNOW?

Date: |

Telegram Be The Next Best SPAC

I have no inside knowledge of a potential stock listing of the popular anti-Whatsapp messaging app, Telegram. But I know this much, judging by most people I talk to, especially crypto investors, if Telegram ever went public, people would gobble it up. I know I would. I’m waiting for it. So is Sergei Sergienko, who claims he owns $800,000 of Telegram’s pre-initial coin offering (ICO) tokens. β€œIf Telegram does a SPAC IPO, there would be demand for this issue. It would probably outstrip the interest we saw during the ICO. Why? Because as of right now Telegram looks like a liberal application that can accept anyone - right after WhatsApp and others have turn on the censorship,” he says.

Launched in 2013, Telegram allows users to broadcast messages to a following via β€œchannels”, or create public and private groups that are simple for others to access. Users can also send and receive large data files, including text and zip files, directly via the app.The platform said it has more than 500m active users, and topped 1bn downloads in August, according to data from SensorTower.C Language ‍ from ca


Telegram C Language πŸ‘¨β€πŸ’»
FROM USA